package recycle.impl;

import org.springframework.stereotype.Service;
import recycle.pojo.Admin;
import recycle.dao.AdminMapper;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import recycle.utils.Page;
import javax.annotation.Resource;
import recycle.vo.AdminParam;
import recycle.service.AdminService;
/**
* 描述：后台管理员信息表 服务实现层接口
* @author 孙冉
* @date 2019/07/22
*/
@Service
public class AdminServiceImpl implements AdminService {
	@Resource
	private AdminMapper adminMapper;
 	
 	/**
    * 描述：根据Id获取Admin对象
    */
    public Admin findById(Serializable adminId){
    	return adminMapper.findById(adminId);
    }
    /**
    * 描述：获取所有的Admin对象
    */
    public List<Admin> findAll(){
    	return adminMapper.findAll();
    }

	/**
    * 描述：新增保存Admin对象
    */
    public int save(Admin admin){
    	return  adminMapper.save(admin);
    }

	/**
    * 描述：根据Id删除Admin对象
    */
    public int delete(Serializable adminId){
    	return  adminMapper.delete(adminId);
    }
	
	/**
    * 描述：更新Admin对象
    */
    public int update(Admin admin){
    	return  adminMapper.update(admin);
    }
    
    /**
     * 根据不确定的条件，动态查询
     */
    public List<Admin> query(AdminParam param){
    	return  adminMapper.query(param);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(AdminParam param){
    	Page page = new Page();
    	if(param.isPage()){
			int totalCount = adminMapper.getCount(param);
			int totalPageCount = (totalCount-1)/page.getPageSize()+1;
			if(param.getPageIndex()<1){
				param.setPageIndex(1);
			}else if(param.getPageIndex()>totalPageCount){
				param.setPageIndex(totalPageCount);
			}
			List list = adminMapper.query(param);

			page.setTotalCount(totalCount);
			page.setTotalPageCount(totalPageCount);
    		page.setPageNo(param.getPageIndex());
    		page.setPageSize(param.getSize());
			page.setList(list);
		}
    	return page;
    	
    }

	@Override
	public List<Admin> findByadminId(int adminId) {
		return adminMapper.findByadminId(adminId);
	}

	@Override
	public List<Admin> findByResponsible(String responsible) {
		return adminMapper.findByResponsible(responsible);
	}

	@Override
	public List<Admin> findByType(String type) {
		return adminMapper.findByType(type);
	}

    @Override
    public Admin findByOther1(String other1) {
        return adminMapper.findByOther1(other1);
    }

    @Override
	public Admin findByNameAndPassword(String other1, String password,int type) {
		return adminMapper.findByNameAndPassword(other1,password,type);
	}

	@Override
	public List<Admin> findAllAdmin() {
		return adminMapper.findAllAdmin();
	}

	@Override
	public int saveNew(Admin admin) {
		return adminMapper.saveNew(admin);
	}

	@Override
	public Admin findByNameAndType(String other1, int type) {
		return adminMapper.findByNameAndType(other1,type);
	}

}
